import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_module/bloc/event/second_event.dart';
import 'package:flutter_module/bloc/repository/second_page_respsitory.dart';
import 'package:flutter_module/bloc/second_bloc.dart';
import 'package:flutter_module/pages/root_page/page_list.dart';

class SecondPage extends StatefulWidget {
  const SecondPage({super.key});

  @override
  _SecondPage createState() => _SecondPage();
}

class _SecondPage extends State<SecondPage> {
  @override
  Widget build(BuildContext context) {
    //在页面中接收状态与发送事件：
    // 使用BlocProvider来提供SecondBloc
    return BlocProvider<SecondBloc>(
      create: (context) =>
          SecondBloc(secondPageRepository: SecondPageRepository())
            ..add(RefreshEvent()), //添加..add(RefreshEvent())触发下拉刷新
      child: const PageList(), //PageList：要单独的写在一个类中，否则_onRefresh和_loadMore会出现报错
    );
  }
}
